package com.haier.cloudremote;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.haier.cloudremote.common.LogOperation;
import com.haier.cloudremote.common.SLog;
import com.haier.cloudremote.common.SendMail;
import com.haier.cloudremote.common.TroubleShooting;
import com.haier.cloudremote.protocal.CAEProtocal;
import com.haier.cloudremote.protocal.ConnectManager;
import com.haier.cloudremote.util.FileUtil;

public class WelcomeTwoActivity extends Activity {
    /** Called when the activity is first created. */
	private StringBuffer debugBuffer = null;// 记录debug按键
	
	private LinearLayout layout;
	private String filePath;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 设置全屏
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.welcome);
        
        ActivityStackControlUtil.add(this); 
		
        layout = (LinearLayout) findViewById(R.id.welcome_layout);
   
    }

    @Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		Bitmap bm = FileUtil.readBitMap(this, R.drawable.intro2bg);
		layout.setBackgroundDrawable(new BitmapDrawable(bm));
	}

	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
		layout.setBackgroundDrawable(null);
	}

	// log：debug开关
    // 5,6,4 关闭/开启 debug，调出debug窗口
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		SLog.d("ssc", "onKeyDown-----KeyCode()"+event.getKeyCode());
		switch (event.getKeyCode()) {
		case 12:// 5
			debugBuffer = new StringBuffer();
			debugBuffer.append("l");
			SLog.d("ssc", "11-----debugBuffer=="+debugBuffer);
			return false;

		case 13:// 6
			if(debugBuffer!=null){
				debugBuffer.append("o");
				SLog.d("ssc", "13-----debugBuffer=="+debugBuffer);
				return false;
			}
			break;

		case 11:// 4
			if(debugBuffer!=null){
				debugBuffer.append("g");
				TroubleShooting troubleShooting = new TroubleShooting(WelcomeTwoActivity.this, debugBuffer);
				debugBuffer = new StringBuffer();

				return false;
			}
			
			break;
		
		case KeyEvent.KEYCODE_DPAD_RIGHT:
		case KeyEvent.KEYCODE_ENTER:
				Intent intent = new Intent();
				intent.setClass(WelcomeTwoActivity.this, HDMIActivity.class);
				startActivity(intent);
				return false;
		case KeyEvent.KEYCODE_DPAD_LEFT:
			finish();
			return false;
		default:
			break;
		}
		return super.onKeyDown(keyCode, event);
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		 //移出管理栈
        ActivityStackControlUtil.remove(this); 
	}
    
	/**
	 * 回收背景图片
	 */
	private void gatRecycle(){
		BitmapDrawable gatLayoutbd = (BitmapDrawable)layout.getBackground();
		gatLayoutbd.getBitmap().recycle();
	}
}